package main

import "fmt"

/**
多态
*/
//本质是一个指针
type AnimalIF interface {
	Sleep()
	GetColor() string
	GetType() string
}

// 三个必须全部重写
//具体的类
type Cat struct {
	color string
}

func (c *Cat) Sleep() {
	fmt.Println("cat sleep")
}
func (c *Cat) GetColor() string {
	return c.color
}
func (c Cat) GetType() string {
	return "Cat"
}

type Dog struct {
	color string
}

func (c *Dog) Sleep() {
	fmt.Println("Dog sleep")
}
func (c *Dog) GetColor() string {
	return c.color
}
func (c Dog) GetType() string {
	return "Dog"
}
func showAnimal(animalIF AnimalIF) {
	animalIF.Sleep()
	fmt.Println(animalIF.GetColor(), animalIF.GetType())

}
func main() {
	//接口的数据类型，父类指针
	/*var animal AnimalIF
	animal = &Cat{"Green"}
	animal.Sleep()
	animal = &Dog{"Yellow"}*/

	c := &Cat{"Green"}
	d := &Dog{"Yellow"}
	showAnimal(c)
	fmt.Println()
	showAnimal(d)

}
